package cn.edu.djtu.fw.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	/**
	 * 时间转字符串
	 * @param Date
	 * @param format "yyyy-MM-dd HH:mm:ss"
	 * @return String
	 */
	public static String dateToString(Date date, String format) {
		String result = "";
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		if (date != null) {
			result = sdf.format(date);
		}
		return result;
	}

	/**
	 * 字符串转时间
	 * @param str 要解析的字符串
	 * @param format "yyyy-MM-dd HH:mm:ss"
	 * @return
	 * @throws Exception
	 */
	public static Date stringToDate(String str, String format) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.parse(str);
	}
}
